package jjn.round2;

import commons.ListNode;

/**
 * @author Jiang Jining
 * @since 2023-05-07 0:10
 */
public class Offer22_GetLastKNode {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode first = head;
        ListNode second = head;
        for (int i = 0; i < k; i++) {
            first = first.next;
        }
        while (first != null) {
            first = first.next;
            second = second.next;
        }
        return second;
    }
}
